<template>
  <div class="UserPage">
    <van-nav-bar
  title="登录"
  left-text=""

  left-arrow
  @click-left="onClickLeft"

/>
  <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button class="bnt" round block type="info" native-type="submit">登录</van-button>
  </div>
  <p @click="add">注册账号</p>
</van-form>

  </div>
</template>

<script>
import { Toast } from 'vant'
import { login } from '@/api/user'
import { setToken } from '@/utils/storage'
export default {
  name: 'LoPage',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async  onSubmit (values) {
      // console.log('submit', values)
      // this.username = ''
      // this.password = ''
      // this.$router.push('/Login')
      const res = await login(values)
      console.log(res)
      setToken(res.data.data.token)
      Toast('登录成功')
      this.$router.push('/')
    },
    add () {
      this.$router.push('/Register')
      // console.log(1)
    },
    onClickLeft () {
      Toast('返回')
    }
  }
}
</script>

<style lang="less" scoped>
.bnt{
  border-radius: 0;

}
p{font-size: 16px;
margin-left: 300px;
}
</style>
